package de.dlrg.wms.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;

import de.dlrg.wms.model.NullClasses.AgeClassNull;
import de.dlrg.wms.model.NullClasses.DisciplineNull;

@javax.persistence.Entity
public class AgeClass {
	
	public static AgeClass AgeClassNull = new AgeClassNull();
	
	private static final long serialVersionUID = 140873997833404916L;
	private String calculationFormula = "";
	
	@Size(min=1)
	@ManyToMany(fetch=FetchType.EAGER)
	private List<Discipline> discipline = new ArrayList<Discipline>();

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@NotEmpty
	private String name = "";

	public static AgeClass AgeClass() {
		return new AgeClass();
	}
	
	public String getCalculationFormula() {
		return calculationFormula;
	}

	public List<Discipline> getDiscipline() {
		return discipline;
	}
	
	public AgeClass addDiscipline(Discipline discipline) {
		this.discipline.add(discipline);
		return this;
	}

	public Long getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public AgeClass setCalculationFormula(String calculationFormula) {
		this.calculationFormula = calculationFormula;
		return this;
	}

	public AgeClass setDiscipline(List<Discipline> discipline) {
		this.discipline = discipline;
		return this;
	}

	public AgeClass setId(Long id) {
		this.id = id;
		return this;
	}

	public AgeClass setName(String name) {
		this.name = name;
		return this;
	}
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof AgeClassNull) {
			return false;
		}
		if (obj instanceof AgeClass) {
			AgeClass ageClass = (AgeClass) obj;
			boolean ret = (ageClass.getId().equals(this.getId()));
			return ret;
		}
		return super.equals(obj);
	}
}
